package com.koalac.ironman.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

	public static String getTimeDescription(String timeStamp){
	    if (StringUtils.isEmpty(timeStamp)) {
		return "未知时间";
	    }
		String time = StringUtils.timestamp2String(timeStamp,
				StringUtils.DEFAULT_DATE_PATTERN);
		long currentTimeStamp = System.currentTimeMillis() / 1000;
		String currentTime = StringUtils.timestamp2String(String.valueOf(currentTimeStamp),
				StringUtils.DEFAULT_DATE_PATTERN);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long dateDIF = 0;
		try {
			Date date = simpleDateFormat.parse(time);
			Date currentDate = simpleDateFormat.parse(currentTime);
			dateDIF = currentDate.getTime() - date.getTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		/**
		 * 秒
		 */
		if(dateDIF/1000 < 60){
			return "刚刚";
		}
		/**
		 * 分
		 */
		if(dateDIF/(1000 * 60) < 60){
			return dateDIF/(1000 * 60) + "分钟前";
		}
		/**
		 * 时
		 */
		if(dateDIF/(1000 * 60 * 60) < 24){
			return dateDIF/(1000 * 60 * 60) + "小时前";
		}
		
		/**
		 * 天
		 */
		if(dateDIF/(1000 * 60 * 60 * 24) < 365){
			return dateDIF/(1000 * 60 * 60 * 24) + "天前";
		}
		
		return StringUtils.timestamp2String(String.valueOf(timeStamp),
				StringUtils.MDHM_DATE_PATTERN);
		
	}
	
}
